package com.wuwangfu.transfor;

import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @Author jcshen
 * @Date 2023-02-23
 * @PackageName:com.wuwangfu.transfor
 * @ClassName: UnionTransf
 * @Description:
 * @Version 1.0.0
 *
 * https://nightlies.apache.org/flink/flink-docs-release-1.14/docs/dev/datastream/operators/overview/#union
 * union要求两个流中数据的类型必须一致，合并为一条流
 */
public class UnionTransf {

    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<String> line = env.socketTextStream("localhost", 8888);
        DataStreamSource<String> word = env.socketTextStream("localhost", 9999);

        DataStream<String> unioned = line.union(word);

        unioned.print();

        env.execute();
    }
}
